package com.onstar.cn.api;

import com.onstar.cn.api.framework.ClazzInjectUtils;
import com.onstar.cn.api.framework.annotation.Path;
import com.onstar.cn.api.framework.annotation.PathParams;
import com.onstar.cn.api.framework.annotation.RequestMapping;

import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.mag.joinme.RegisterRequestEntity;

/**
 * 
* @ClassName: JoinmeService 
* @Description: 注册，升级接口
* @author 6335yz
* @date 2015年9月6日 下午2:47:43
 */
@Path("/msp/api/v3/user")
public class JoinmeService {

    private String serverURL;

    public JoinmeService(String serverURL) {
        this.serverURL = serverURL;
    }

    /**
     * 注册为车主
     *
     * @param requestEntity
     * @param entity
     * @return
     */
    @RequestMapping("/register/checkUnique")
    public RequestEntity registercheckUnique(RequestEntity requestEntity, RegisterRequestEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "registercheckUnique", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        if (entity != null) {
            requestEntity.setBody(GsonHelper.toJson(entity));
        }
        return requestEntity;
    }

//	/**
//	 * 注册为车主
//	 * @param requestEntity
//	 * @param entity
//	 * @return
//	 */
//  @Deprecated
//	@RequestMapping("/register/subscriber")
//	public RequestEntity registerToSubscriber(RequestEntity requestEntity, RegisterRequestEntity entity) {
//		if (requestEntity == null) {
//			requestEntity = new RequestEntity();
//		}
//		String url = ClazzInjectUtils.injectUrl(getClass(), "registerToSubscriber", requestEntity, entity);
//		requestEntity.setUrl(serverURL + url);
//		return requestEntity;
//	}

    /**
     * 注册为车主
     *
     * @param requestEntity
     * @param entity
     * @return
     */
    @RequestMapping("/register/subscriberv2")
    public RequestEntity registerToSubscriber(RequestEntity requestEntity, RegisterRequestEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "registerToSubscriber", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        return requestEntity;
    }

    /**
     * 注册为潜客
     *
     * @param requestEntity
     * @param entity
     * @return
     */
    @RequestMapping("/register/visitor")
    public RequestEntity registerToVisitor(RequestEntity requestEntity, RegisterRequestEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "registerToVisitor", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        if (entity != null) {
            requestEntity.setBody(GsonHelper.toJson(entity));
        }
        return requestEntity;
    }

    /**
     * 潜客升车主
     *
     * @param requestEntity
     * @param entity
     * @return
     */
//    @RequestMapping("/register/upgrade")
//    public RequestEntity registerToUpgrade(RequestEntity requestEntity, RegisterRequestEntity entity) {
//        if (requestEntity == null) {
//            requestEntity = new RequestEntity();
//        }
//        String url = ClazzInjectUtils.injectUrl(getClass(), "registerToUpgrade", requestEntity, entity);
//        requestEntity.setUrl(serverURL + url);
//        return requestEntity;
//    }

    /**
     * 发送验证码
     * @param requestEntity
     * @param entity
     * @return
     */
	@RequestMapping("/register/code")
	public RequestEntity registerCode(RequestEntity requestEntity, RegisterRequestEntity entity) {
		if (requestEntity == null) {
			requestEntity = new RequestEntity();
		}
		String url = ClazzInjectUtils.injectUrl(getClass(), "registerCode", requestEntity, entity);
		requestEntity.setUrl(serverURL + url);
		if(entity!=null) {
			requestEntity.setBody(GsonHelper.toJson(entity));
		}
		return requestEntity;
	}

    /**
     * Validation input code
     *
     * @param requestEntity
     * @param entity
     * @return
     */
//	@RequestMapping("/register/code/validation")
//	public RequestEntity registerValidationCode(RequestEntity requestEntity, RegisterRequestEntity entity) {
//		if (requestEntity == null) {
//			requestEntity = new RequestEntity();
//		}
//		String url = ClazzInjectUtils.injectUrl(getClass(), "registerValidationCode", requestEntity, entity);
//		requestEntity.setUrl(serverURL + url);
//		requestEntity.setBody(GsonHelper.toJson(entity));
//		return requestEntity;
//	}
    @RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/serviceEntitlement")
    public String getServiceList(RequestEntity requestEntity, @PathParams(value = "subscriberID") String subscriberID,
                                 @PathParams(value = "accountID") String accountID,
                                 @PathParams(value = "vin") String vin) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getServiceList", requestEntity, subscriberID, accountID, vin);
        requestEntity.setUrl(serverURL + url);
        return url;
    }

    /**
     * @return RequestEntity
     * @Title: checkIsNeedInputCaptcha
     * @Description: 查询是否需要输入图片验证码
     */
    @RequestMapping("/register/captcha/required")
    public RequestEntity checkIsNeedInputCaptcha(RequestEntity requestEntity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "checkIsNeedInputCaptcha", requestEntity);
        requestEntity.setUrl(serverURL + url);
        return requestEntity;
    }


    /**
     * @param requestEntity
     * @param captchaId
     * @return String
     * @Title: getImageCaptcha
     * @Description: 根据图片验证码Id获取验证码图片
     */
    @RequestMapping("/register/captcha/generate/{captchaId}")
    public RequestEntity getImageCaptcha(RequestEntity requestEntity, @PathParams(value = "captchaId") String captchaId) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getImageCaptcha", requestEntity, captchaId);
        requestEntity.setUrl(serverURL + url);
        return requestEntity;
    }


    /**
     * @param requestEntity
     * @param entity
     * @return RequestEntity
     * @Title: checkIsCaptchaValue
     * @Description: 检查输入的图片验证码是否正确
     */
    @RequestMapping("/register/captcha/validate/{captchaId}/{captchaValue}")
    public RequestEntity checkIsCaptchaValue(RequestEntity requestEntity, @PathParams(value = "captchaId") String captchaId
            , @PathParams(value = "captchaValue") String captchaValue) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "checkIsCaptchaValue", requestEntity, captchaId, captchaValue);
        requestEntity.setUrl(serverURL + url);
        return requestEntity;
    }


}
